package com.qiaoba.common.base.entity;

import cn.hutool.http.HttpStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

/**
 * 基础分页封装对象
 *
 * @author ailanyin
 * @date 2023-09-03 18:25:13
 */
@Getter
@Setter
@NoArgsConstructor
public class BasePage<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 总记录数
     */
    @Schema(description = "总记录数")
    public long total;

    /**
     * 列表数据
     */
    @Schema(description = "列表数据")
    public List<T> rows;

    /**
     * 消息状态码：200
     */
    public final int code = HttpStatus.HTTP_OK;


    public BasePage(List<T> list, long total) {
        this.rows = list;
        this.total = total;
    }

    public static <T> BasePage<T> build(Long total, List<T> list) {
        BasePage<T> basePage = new BasePage<T>();
        basePage.setRows(list);
        basePage.setTotal(total);
        return basePage;
    }

}
